﻿using DesertKharonIrcPlugin.Emotes;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DesertKharonIrcPlugin.GdiPlusRendering
{
    public sealed class DrawableEmote : DrawableBase, IDisposable
    {
        private Emote _emote;

        public DrawableEmote(Emote emote, string authorNickname)
            : base(authorNickname)
        {
            _emote = emote;
            UpdateBitmaps();
        }

        private bool _lastIsLoaded = false;
        private int _lastAnimationFrame = -1;
        protected override void UpdateBitmaps()
        {
            if (_emote.IsLoaded)
            {
                if (_lastIsLoaded == false)
                    SetBitmap(_emote.Bitmap, false);

                _lastAnimationFrame = -1;
                _lastIsLoaded = true;
            }
            else
            {
                if (_emote.LoadingAnimation.CurrentFrame != _lastAnimationFrame)
                    SetBitmap(_emote.LoadingAnimation.Bitmap, false);

                _lastAnimationFrame = _emote.LoadingAnimation.CurrentFrame;
                _lastIsLoaded = false;
            }
        }
    }
}
